<script>
	/*open_phone_client_dialog() {
	 $("#div_phone_client").show();
	 $("#div_phone_client").dialog({
	 title : 'Numeros de telephone',
	 resizable : false,
	 height : 'auto',
	 width : 'auto',
	 modal : true
	 });
	 }*/

	$('#create').button({
		text : true,
	}).click(function() {
		//open_phone_client_dialog()
	});

	//Creation de l'accordeon
	$(function() {
		$("#accordion").accordion();
	});

	//Création de button
	$(function() {
		$("b,.vider").button().click(function(event) {
			event.preventDefault();
		});
	});

	//Auto completion

	$(function() {
		$("#tags").autocomplete({
			source : "/autocompletion_poudre",
			minLength : 1,
			autoFocus : true,
		});
	});
	////////////////////////////
	
	function showdetails(exp) {
			//exp = $("#exp")
			chercher(exp)
			$(".toggler_liste_poudres").hide();
			$(".toggler_search").hide();
			$(".toggler_agenda_poudre").hide();
			$(".toggler_create_poudre").hide()
			
			var selectedEffect = "slide";
			// most effect types need no options passed by default
			var options = {};
			// some effects have required parameters
			if (selectedEffect === "scale") {
				options = {
					percent : 0
				};
			} else if (selectedEffect === "transfer") {
				options = {
					to : "#button",
					className : "ui-effects-transfer"
				};
			} else if (selectedEffect === "size") {
				options = {
					to : {
						width : 200,
						height : 60
					}
				};
			}
			// run the effect
			$(".toggler_agenda_poudre").effect(selectedEffect, options, 500);
		}

	function chercher(e) {
		var lien = "/search_poudre?term="+e.replace(/ /g, '_')
		$.getJSON(lien, function(data) {
			//$("#user_list").empty();
			$("#tab_agenda").empty()
			html = "";
			for (var i = 0; i < data.length; i++) {
				var row = (i % 2)
				html += "<tr" + " class =row" + row + ">" + "<th>" + data[i][0] + "</th>" + "<th>" + data[i][1] + "</th>" + "<th>" + data[i][2] + "</th>" + "<th>" + data[i][3] + "</th>" + "</tr>"

			}
			$("#poudre").empty()
			$("#poudre").append($("#tags").val())
			$("#tab_agenda").append(html)
		});
	}
	
	////////////////////////////////////////////////////////
	$(function() {
		function hideall() {
			$(".toggler_liste_poudres").hide();
			$(".toggler_search").hide();
			$(".toggler_agenda_poudre").hide();
			$(".toggler_create_poudre").hide()
		}
		// run the currently selected effect
		function runEffect(cequilfaut) {
			// get effect type from
			var selectedEffect = "slide";
			// most effect types need no options passed by default
			var options = {};
			// some effects have required parameters
			if (selectedEffect === "scale") {
				options = {
					percent : 0
				};
			} else if (selectedEffect === "transfer") {
				options = {
					to : "#button",
					className : "ui-effects-transfer"
				};
			} else if (selectedEffect === "size") {
				options = {
					to : {
						width : 200,
						height : 60
					}
				};
			}
			// run the effect
			$(cequilfaut).effect(selectedEffect, options, 500);
		};
		$("#search_button").click(function(e) {
			//chercher()
			hideall()
			e.preventDefault()
			runEffect(".toggler_search");
			return false;
		});
		$("#liste_button").click(function(e) {
			hideall()
			e.preventDefault()
			runEffect(".toggler_liste_poudres");
			return false;
		});
		$("#button").click(function(e) {
			exp = $("#tags").val()
			chercher(exp)
			hideall()
			e.preventDefault()
			runEffect(".toggler_agenda_poudre")
			return false;
		});
		$("#search_button").click(function(e) {
			//chercher()
			hideall()
			e.preventDefault()
			runEffect(".toggler_search");
			return false;
		});
		
		$("#create").click(function(e) {
			//chercher()
			hideall()
			e.preventDefault()
			runEffect(".toggler_create_poudre");
			return false;
		});
		/*$("#details").click(
			function showdetails(exp) {
			//exp = $("#exp")
			chercher(exp)
			hideall()
			e.preventDefault()
			runEffect(".toggler_agenda_poudre");
			return false;
		}//);*/

		$(".toggler_liste_poudres").hide();
		$(".toggler_search").hide();
		$(".toggler_agenda_poudre").hide();
		$(".toggler_create_poudre").hide()
	});
	// set effect from select menu value
	$(function() {
		$("#menu").menu();
	}); 

	$(function() {
		$("#datepicker").datepicker();
	}); 
